from math import gcd
from typing import *


class Solution:
    def maxScore(self, nums: List[int]) -> int:

        def gcd(a, b):
            return b if a % b == 0 else gcd(b, a % b)

        def lcm(a, b):
            return a // gcd(a, b) * b

        def f(nums, k):
            g = l = nums[0] if k != 0 else nums[1]
            for i in range(1, len(nums)):
                if i != k:
                    g = gcd(g, nums[i])
            for i in range(1, len(nums)):
                if i != k:
                    l = lcm(l, nums[i])
            return g * l

        ans = f(nums, -1)
        for i in range(len(nums)):
            ans = max(ans, f(nums, i))
        return ans


def gcd(a, b):
    return b if a % b == 0 else gcd(b, a % b)


def lcm(a, b):
    return a // gcd(a, b) * b


# print(lcm(12, 18))
# print(18 % 12)
so = Solution()
print(so.maxScore([2, 4, 8, 16]))
